package com.example.demo0331.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo0331.entity.Shop;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShopMapper extends BaseMapper<Shop> { // 也可以不继承BaseMapper，完全自己声明所有方法
    @Select("select id, name, address from shop")
    public List<Shop> find();

    @Select("select id, name, address from shop where id=#{id}")
    public Shop findById(int id);

//    @Insert("insert into shop (name, address) values (#{name}, #{address})")
//    public int insert(Shop shop);

    @Delete("delete from shop where id=#{id}")
    public int delete(int id);

    @Update("update shop set name=#{name}, address=#{address} where id=#{id}")
    public int update(Shop shop);

    @Select("select id, name, address from shop")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "address", property = "address"),
            @Result(column = "id", property = "goodsList", javaType = List.class,
                many = @Many(select = "com.example.demo0331.mapper.GoodsMapper.selectByShopId")
            )
    })
    public List<Shop> allWithGoods();
}
